layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var outboundSubsidyTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),outboundSubsidyTable)
            }
        },
        initTable:function(){
            outboundSubsidyTable = table.render({
                elem : '#outboundSubsidyTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/outboundSubsidy/Acceptancelist.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },
                    {

                        field : 'id',
                            title : 'Id',
                        fixed:'left',
                            width : 60,
                    },
                    {

                     field : 'name',
                         title : '姓名',
                        align: 'center',
                        width:"165"
                     },
                    {

                        field : 'subsidyCategoryText',
                        title : '申报补贴类别',
                        align: 'center',
                        width:"180"
                    },
                    {

                        field : 'subsidyAmount',
                        title : '补贴金额',
                        align: 'right',
                        width:"135",templet:function (d) {
                        return Common.getMoney(d.subsidyAmount);
                    }
                    },
                    {

                        field : 'outboundTime',
                        title : '出站时间',
                        align: 'center',
                        width:"165"
                    },
                {

                    field : 'businessState', 
                        title : '业务状态',
                    align: 'center',
                    width:"90"
                },
                {

                    field : 'dateReporting', 
                        title : '上报日期',
                    align: 'center',
                    width:"165"
                }
        ] ]

        });

            table.on('checkbox(outboundSubsidyTable)', function(obj){
                var outboundSubsidy = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),outboundSubsidyTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/outboundSubsidy/add.do";
                    Common.openDlg(url,"博士后出站补贴管理>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"outboundSubsidyTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/outboundSubsidy/edit.do?id="+data.id;
                    Common.openDlg(url,"博士后出站补贴管理>编辑");
                },
                find : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"outboundSubsidyTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/outboundSubsidy/findenterprise.do?id="+data.id;
                    Common.openDlg(url,"博士后出站补贴受理>查看");
                },
                process : function() { // 获取选中数目
                    var businessType = Common.businessType.outboundSubsidy;
                    var data = Common.getOneFromTable(table,"outboundSubsidyTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/businessProcess/index.do?businessType="+businessType+"&businessId="+data.id;
                    Common.openDlg(url,"流程信息>编辑");
                },
                acceptance : function() { // 获取选中数目
                    var data = Common.UnableToFirstTrial(table,"outboundSubsidyTable");
                    if(data==null){
                        return ;
                    }
                    Common.post("/cms/common/acceptanceVaild.json?declarationType=outbound_subsidy", {}, function(dataRes) {
                        var url = "/cms/outboundSubsidy/acceptance.do?id="+data.id;
                        Common.openDlg(url,"博士后出站补贴受理>受理");
                    })
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delBatch();
                    });
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('enterpriseindex',view);

});